
from mini_tools.mytools import *
import concurrent.futures as thddd



ms = sqlseverDB('{SQL Server}', SQL_SERVER, 'SuMaiTongPol', SQL_USER, SQL_PWD)


qqkws=[]
# 上传SKU并执行插入数据库操作
def upload000(data):
    global qqkws
    pid,pname=data
    flag=False
    for qqkw in qqkws:

        if isContain(qqkw,pname):
            flag=True
            break
    
    aff=0
    if flag:
        print(f'pid:{pid}的标题包含侵权词标记')
        aff=ms.ExecNoQuery('update ALLproduct set pw=0 where pid=?',(pid,))
        print(f'pid:{pid}')

    return pid,flag,aff

def pppp():
    global qqkws
    print(f'获取当前波兰侵权词...')
    rs_qqc=ms.ExecQuery('select qcontent from qqc where qtype=?',('波兰语',))
    qqkws=[r[0] for r in rs_qqc]
    rs= ms.ExecQuery('select pid,BiaoTi from ALLproduct where pw=1')
    print(f'共有{len(rs)}标题待检查侵权....')
    with thddd.ThreadPoolExecutor(max_workers=20) as t:

        tasks=[t.submit(upload000,r) for r in rs]
        task_count=len(tasks)
        for  t0 in thddd.as_completed(tasks):
            try:
                res=t0.result()
            except Exception as e:
                print(f'线程错误 => {e}')
            task_count-=1
            print(f'任务剩余:{task_count}\n')
    

pppp()
